<template>
  <div>
    <div class="toolbar">
      <el-button type="primary" @click="showDetail('create')">新增</el-button>
    </div>
    <el-table :data="customers" v-loading="loading">
      <el-table-column prop="customerCode" label="客户代码" width="150"></el-table-column>
      <el-table-column prop="customerName" label="客户名称"></el-table-column>
      <el-table-column prop="contact" label="联系人" width="150"></el-table-column>
      <el-table-column prop="telephone" label="联系电话" width="150"></el-table-column>
      <el-table-column prop="isdeleted" width="100" label="状态">
        <template scope="scope">
          <el-tag
            :type="scope.row.isdeleted === '1' ? 'success' : 'gray'"
            close-transition>{{scope.row.isdeleted === '1' ? '在用' : '停用'}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="200" inline-template align="center">
        <template>
          <el-button type="text" size="small" @click="showDetail(row.pkid)">查看详情</el-button>
          <el-button type="text" size="small" @click="showOrgs(row.pkid)">组织网点信息</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination class="page"
      @current-change="handleCurrentChange"
      :current-page="1"
      :page-size="10"
      layout="total, prev, pager, next, jumper"
      :total="page.totalRecord">
    </el-pagination>
  </div>
</template>
<style scoped>
  .page{
    text-align: right;
    margin: 10px 0px;
  }
</style>
<style>
  .toolbar{
    padding: 10px;
  }
</style>
<script>
  import customerApi from '../../../api/crm/customerApi'

  export default {
    data () {
      return {
        customers: [],
        page: {},
        loading: false
      }
    },
    created () {
      this.loading = true
      customerApi.queryByPage(1, 10).then(resp => {
        this.customers = resp.body.data
        this.page = resp.body.page
        this.loading = false
      })
    },
    methods: {
      handleCurrentChange: function (pageNo) {
        this.loading = true
        customerApi.queryByPage(pageNo, 10).then(resp => {
          this.customers = resp.body.data
          this.page = resp.body.page
          this.loading = false
        })
      },
      showDetail: function (id) {
        this.$router.push({name: 'customerDetail', params: {id: id}})
      },
      showOrgs: function (id) {
        this.$router.push({name: 'customerOrgs', params: {customerid: id}})
      }
    }
  }
</script>